package main

import "fmt"

type Reader interface{
    ReadBook()
}

type Writer interface{
    WriteBook()
}

type Book struct{

}

func (this *Book) ReadBook(){
    fmt.Println("read a Book")
}

func (this *Book) WriteBook(){
    fmt.Println("write a Book")
}

func main(){
    var a string
    //pair<static type:string, value:"abcd">
    a = "abcd"

    //任何一个类型都有pair <static type:string, value:"abcd">
    var allType interface{}
    allType = a

    str,_ := allType.(string)

    fmt.Println(str)

    //b:pair<type:Book, value:book{}地址>
    b := &Book{}

    var r Reader
    //r:pair<type:Book, value:book{}地址>
    r = b
    r.ReadBook()

    var w Writer
    //r:pair<type:Book, value:book{}地址>
    w = r.(Writer)  //为什么断言成功，因为w r type是一致
    w.WriteBook()
}